<#-- @ftlvariable name="entity" type="com.xci.edu.core.entity.EduStudent" -->
<#include "/sys/_layout.ftl">
<#assign allowInsert=sysWeb.auth("background.eduStudent.insert")/>
<#assign allowUpdate=sysWeb.auth("background.eduStudent.update")/>
<#assign allowDelete=sysWeb.auth("background.eduStudent.delete")/>
<#assign allowExport=sysWeb.auth("background.eduStudent.export")/>
<#assign allowAuditStudent=sysWeb.auth("background.eduStudent.auditStudent")/>
<#assign allowSetStatusOne=sysWeb.auth("background.eduStudent.allowSetStatusOne")/>
<#assign allowSetExamPro=sysWeb.auth("background.eduStudent.setExamPro")/>

<!doctype html>
<html>
<head>
    <@pageHeader/>
</head>
<body>
<@pageLoading/>
<div id="gridtoolbar">
    <div>
        <form id="gridform" class="jxlayout-form form-inline jxform">
            <input type="hidden" id="status" name="status" value=""/>
            <div class="form-group">
                <input name="name" class="form-control w-250px" placeholder="请输入姓名" autocomplete="off">
            </div>
            <div class="form-group" >
                <select class="form-control jxselect" name="eduCategoryId" data-select-submit="true" data-width="140" data-allow-clear="false">
                    <option value=" " selected>全部科目</option>
                    <@eduCategorySelectOption selectedValue=entity.eduCategoryId></@eduCategorySelectOption>
                </select>
            </div>
            <div class="form-group" >
                <select class="form-control jxselect" name="planId" data-select-submit="true" data-width="140" data-allow-clear="false">
                    <option value=" " selected>全部培训计划</option>
                    <@eduPlanSelectOption selectedValue=entity.planId></@eduPlanSelectOption>
                </select>
            </div>
            <button class="btn btn-primary ml-5" type="submit">
                <i class="fa fa-search"></i> 查询
            </button>
            <div class="btn-group">
                <@echo test=allowInsert>
                <a class="btn btn-default" onclick="curd.createData()">
                    <i class="icon-plus"></i> 报名
                </a>
                </@echo>
                <@echo test=allowUpdate>
                    <a class="btn btn-default" onclick="curd.editData()">
                        <i class="icon-pencil"></i> 修改
                    </a>
                </@echo>
                <@echo test=allowAuditStudent>
                    <a class="btn btn-default" onclick="auditStudent()">
                        <i class="icon-pencil"></i> 报名审核
                    </a>
                </@echo>
                <@echo test=allowSetStatusOne>
                    <a class="btn btn-default" onclick="setStatusOne()">
                        <i class="icon-pencil"></i> 退档
                    </a>
                </@echo>
                <@echo test=allowSetExamPro>
                    <a class="btn btn-default" onclick="setExamPro()">
                        <i class="icon-pencil"></i> 预约考试
                    </a>
                </@echo>
                <@echo test=allowDelete>
                    <a class="btn btn-default" onclick="curd.deleteData()">
                        <i class="icon-trash"></i> 删除
                    </a>
                </@echo>
                <@echo test=allowExport>
                    <a class="btn btn-default" onclick="curd.exportData()">
                        <i class="icon-share-alt"></i> 导出
                    </a>
                </@echo>
            </div>
        </form>
    </div>
    <div class="jxtabs-line line-primary border-top-gray" style="margin-bottom: 2px;">
        <ul class="nav nav-tabs">
            <li class="active" data-value="">
                <a data-toggle="tab">全部</a>
            </li>
            <li data-value="0">
                <a data-toggle="tab">预报名</a>
            </li>
            <li data-value="1">
                <a data-toggle="tab">报名中</a>
            </li>
            <li data-value="2">
                <a data-toggle="tab">学习中</a>
            </li>
            <li data-value="3">
                <a data-toggle="tab">准备考试</a>
            </li>
            <li data-value="4">
                <a data-toggle="tab">考试中</a>
            </li>
            <li data-value="5">
                <a data-toggle="tab">完成</a>
            </li>
        </ul>
    </div>
</div>
<table id="grid" data-options="form:'#gridform',toolbar:'#gridtoolbar'">
    <thead>
    <tr>
        <th data-options="field:'ck',checkbox:true"></th>
        <th data-options="title:'学员姓名',field:'name',width:80,align:'left',sortable: false"></th>
        <th data-options="title:'身份证号码',field:'idNumber',width:180,align:'left',sortable: false"></th>
        <th data-options="title:'手机号码',field:'phone',width:120,align:'left',sortable: false"></th>
        <th data-options="title:'地址',field:'address',width:200,align:'left',sortable: false"></th>
        <th data-options="title:'邮箱',field:'email',width:150,align:'left',sortable: false"></th>
        <th data-options="title:'科目名称',field:'eduCategoryName',width:200,align:'left',sortable: false"></th>
        <th data-options="title:'培训计划名称',field:'planName',width:200,align:'left',sortable: false"></th>
        <th data-options="title:'已培训总学时(秒)',field:'trainTotalPeriod',width:120,align:'left',sortable: false"></th>
        <th data-options="title:'状态',field:'status',width:70,align:'left',sortable: false,formatter:formatStatus"></th>
    </tr>
    </thead>
</table>
<@pageFooter/>
<script>
    function formatStatus(v, row, index) {
        if (v == '0') {
            return '<span class="label label-warning">预报名</span>';
        }if (v == '1') {
            return '<span class="label label-info">报名中</span>';
        }if (v == '2') {
            return '<span class="label label-success">学习中</span>';
        }if (v == '3') {
            return '<span class="label label-default">准备考试</span>';
        }if (v == '4') {
            return '<span class="label label-danger">考试中</span>';
        } if (v == '5') {
            return '<span class="label label-primary">完成</span>';
        } else {
            return '<span class="label label-primary"></span>';
        }
    }
    jx.ready(function () {
        window.curd = new jx.GridCurd('#grid', {
            title: '学员信息',
            dialogWidth: '800px',
            dialogHeight: '400px',
            api: {
                grid: '/background/eduStudent/grid',
                create: '/background/eduStudent/create',
                edit: '/background/eduStudent/edit',
                delete: '/background/eduStudent/delete',
                details: '/background/eduStudent/details',
                status: '/background/eduStudent/status',
                export: '/background/eduStudent/export',
                auditStudent: '/background/eduStudent/auditStudent',
                setStatusOne:'/background/eduStudent/setStatusOne',
                setPlan:'/background/eduStudent/setPlan',
                setExamPro:'/background/eduStudent/setExamPro'
            },
            onInit: function (instance) {
                $('.nav-tabs > li').on('click', function () {
                    console.log($(this).data('value'));
                    $('#status').val($(this).data('value'));
                    $('#gridform').find(':submit').click();
                });
            }
        });
    });

    /**
     * 学员预报名报名信息审核
     */
    function auditStudent() {
        if (!curd.gridInstance.hasCheckedRow()) return;
        var ids = curd.gridInstance.getCheckedRowIds();
        jx.ajax({
            url: jx.url(curd.api.auditStudent),
            data: {ids: ids.join()},
            maskMsg: '正在审核信息,请稍等...',
            success: function (result) {
                this.reloadGridData();
                jx.toastr.success('审核信息成功');
            }
        });
    }

    /**
     * 退档
     */
    function setStatusOne() {
        if (!curd.gridInstance.hasCheckedRow()) return;
        var ids = curd.gridInstance.getCheckedRowIds();
        jx.ajax({
            url: jx.url(curd.api.setStatusOne),
            data: {ids: ids.join()},
            maskMsg: '正在退党,请稍等...',
            success: function (result) {
                this.reloadGridData();
                jx.toastr.success('退党成功');
            }
        });
    };

    /**
     * 预约考试
     */
    function setExamPro() {
        if (!curd.gridInstance.hasCheckedRow()) return;
        var ids = curd.gridInstance.getCheckedRowIds();
        var listStudent =curd.gridInstance.getChecked();

        var categoryName ="";
        var categoryId ="";
        var isSetExamPro;
        for(var i=0;i<listStudent.length;i++) {
            isSetExamPro = true;
            var eduCategoryName = listStudent[i].eduCategoryName;
            var eduCategoryId = listStudent[i].eduCategoryId;
            if(i == 0){
                categoryName = eduCategoryName;
                categoryId = eduCategoryId;
            }else{
                if(eduCategoryName !== categoryName){
                    isSetExamPro =false;
                }
                break;
            }
        }
        if(isSetExamPro){
            jx.dialog({
               url: jx.url(curd.api.setExamPro),
               title: '预约考试',
               width: '550px',
               height: '510px',
               params: {
                   ids: ids,
                   categoryId:categoryId
               }
            });
        }else{
            jx.toastr.error('无法同时给不同培训科目的学员,预约考试');
        }
    };
</script>
</body>
</html>